import { defineConfig } from 'vite'
const { createVuePlugin } = require('vite-plugin-vue2')
import path, { resolve ,join} from 'path'
import compressPlugin from "vite-plugin-compression"; //静态资源压缩
import electron from 'vite-plugin-electron'
// vite.config.js
export default defineConfig({
	// publicDir: '/',
	base: "./",
	plugins: [
		createVuePlugin(),
		compressPlugin({ //gzip静态资源压缩
			verbose: true,    // 默认即可
			disable: false,  //开启压缩(不禁用)，默认即可
			deleteOriginFile: false, //删除源文件
			threshold: 10240, //压缩前最小文件大小
			algorithm: 'gzip',  //压缩算法
			ext: '.gz', //文件类型
		}),
		electron({
			main: {
				entry: 'electron/index.js',
				vite: {
					build: {
						sourcemap: false,
						outDir: 'dist/',
					},
				},
			},
			preload:{
				input: {
					// You can configure multiple preload here
					preload: join(__dirname, 'electron/preload/preload.js'),
				  },
				entry: 'electron/preload/preload.js',
				vite: {
					build: {
						sourcemap: false,
						outDir: 'dist/',
					},
				},
			}
		}),
	],
	resolve: {
		extensions: ['.vue', '.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
		alias: {
			// vue2项目别名一般都是@，vue3中一般使用/@/, 为方便使用
			'@': resolve(__dirname, 'src/'),
			'~@': resolve(__dirname, 'src/'),
		},
	},
	server: {
		port: '3000',
		host: '0.0.0.0',
		proxy: {
			'/api': {
				target: 'https://w3cjs.cn', // 凡是遇到 /api 路径的请求，都映射到 target 属性
				changeOrigin: true,
			},
		},
	},
	//生产模式打包配置
	build: {
		outDir: 'dist', //Specify the output directory (relative to project root).
	},
})
